/* 正在进行 */
<template>
  <div>
    <Card :bordered="false" v-if="isShow">
      <p slot="title">正在进行</p>
      <p>
        <Row style="padding:10px 0">
          <Col span="8" offset="16">
          <Input search @on-search="searchBut" v-model="searchButVal" enter-button="搜索" placeholder="请输入关键字" />
          </Col>
        </Row>
        <Row>
          <Col span="24">
          <Table border :columns="columns" :data="listData" :loading="loading" @on-sort-change="sortChange"></Table>
          </Col>
        </Row>
        <Row v-if="hidePage" style="padding:10px 0">
          <Col span="24">
          <Page style="float:right" :total="total" @on-change="changePage" show-total :current.sync="page" />
          </Col>
        </Row>
      </p>
    </Card>
    <rojectProcedures v-if="!isShow" :routerId='routerId' v-on:back-up='isShow=true'></rojectProcedures>
  </div>
</template>

<script>
  import { getTypeInfo } from '../../libs/status'
  import rojectProcedures from './rojectProcedures'
  export default {
    components: {rojectProcedures},
    props: {
      hidePage: {
        default: true,
      },
      pageSize: {
        default: 10,
      },
    },
    data() {
      return {
        searchButVal: "",
        routerId: '',
        isShow: true,
        total: 0,
        page: 1,
        columns: [{
            align: "center",
            title: '项目编号',
            key: 'projectNumber',
            sortable: 'custom'
          },
          {
            align: "center",
            title: '项目名称',
            key: 'projectName'
          },
          {
            align: "center",
            title: '建设单位',
            key: 'buildUnit',
          },
          {
            align: "center",
            title: '类型',
            key: 'reportType',
            sortable: 'custom'
          },
          {
            align: "center",
            title: '创建日期',
            key: 'perjectTime',
            sortable: 'custom'
          },
          {
            align: "center",
            title: '状态',
            key: 'perjectTypeName',
            sortable: 'custom'
          },
          {
            align: "center",
            title: '操作',
            key: 'operation',
            render: (h, params) => {
              return h("div", [
                h(
                  "Button", {
                    props: {
                      type: "primary",
                      size: "small"
                    },
                    style: {
                      marginRight: "5px",
                      color: "#ffffff",
                      background: "#2996ff",
                      border: "none",
                      padding: "0px 5px"
                    },
                    on: {
                      click: () => {
                        this.routerId = params.row.id
                        this.isShow = false
                      }
                    }
                  },
                  "查看"
                ),
                h(
                  "Button", {
                    props: {
                      type: "primary",
                      size: "small",
                      disabled: this.modifyBtn
                    },
                    style: {
                      marginRight: "5px",
                      color: "#ffffff",
                      background: "#2996ff",
                      border: "none",
                      padding: "0px 5px"
                    },
                    on: {
                      click: () => {
                        var Atype = 0
                        console.log(params.row.perjectType)
                        switch (params.row.perjectType) {
                          case '6':
                            Atype = 0
                            break;
                          case '7':
                            Atype = 1
                            break;
                          case '8':
                            Atype = 2
                            break;
                          case '9':
                            Atype = 3
                            break;
                          case '10':
                            Atype = 4
                            break;
                        }

                        this.show(params.index, params.row.id, Atype, params.row.perjectType);
                      }
                    }
                  },
                  "修改"
                )
              ])
            }
          },
        ],
        listData: [],
        loading: true,
        key:'',
        order:'',
        modifyBtn: false,
      }
    },
    created() {
      /* 调取正在进行接口 */
      this.getUnderway(this.page)
    },
    mounted() {
      
    },
    updated(){
      this.getPersonType()
    },
    methods: {
      getPersonType(){
        if(localStorage.getItem('userOrg') == 'Ent'){
          this.modifyBtn = true 
        }
      },
      sortChange(data){
          this.key = data.key
          this.order = data.order
          this.page = 1;
          console.log(this.page);
          this.getUnderway()
      },
      searchBut() {
        this.getUnderway()
      },
      show(index, ProjectId, Atype, PerjectType) {
        console.log(Atype)
        let info = this.listData[index],
          projectId = info.id
        // 跳转到相关页面
        let name = getTypeInfo(info.perjectType, 'route')
        this.$router.push({
          name,
          query: {
            ProjectId,
            Atype,
          }
        })
      },
      getUnderway() {
        this.loading = true
        let ProjectName = this.searchButVal
        axios.get('/projectInformation/findWithState', {
          params: {
            PageIndex: this.page - 1,
            ProjectName,
            PageSize: this.pageSize,
            Key:this.key,
            Order:this.order
          }
        }).then(res => {
          this.loading = false
          if (res._STATUS) {
            // console.log(res)
            // 格式化数据
            if(!res.projectInfo){
              res.count = 0
              res.projectInfo = []
            }else{
              res.projectInfo.forEach((e, i) => {
              switch (e.perjectType) {
                case "1":
                  e['perjectTypeName'] = "创建项目"
                  e['perjectR_type'] = "createProgram"
                  break;
                case "2":
                  e['perjectTypeName'] = "资料收集"
                  e['perjectR_type'] = "dataCollection"
                  break;
                case "3":
                  e['perjectTypeName'] = "现场踏勘"
                  e['perjectR_type'] = "reconnaissanceTrip"
                  break;
                case "4":
                  e['perjectTypeName'] = "环境质量"
                  e['perjectR_type'] = "environmentQuality"
                  break;
                case "5":
                  e['perjectTypeName'] = "报告编制及审核"
                  e['perjectR_type'] = "reportReview"
                  break;
                case "6":
                  e['perjectTypeName'] = "分公司一审"
                  e['perjectR_type'] = "firstInstance"
                  break;
                case "7":
                  e['perjectTypeName'] = "分公司二审"
                  e['perjectR_type'] = "secondInstance"
                  break;
                case "8":
                  e['perjectTypeName'] = "初审"
                  e['perjectR_type'] = "firstTrial"
                  break;
                case "9":
                  e['perjectTypeName'] = "复审"
                  e['perjectR_type'] = "reExamine"
                  break;
                case "10":
                  e['perjectTypeName'] = "终审"
                  e['perjectR_type'] = "lastInstance"
                  break;
                case "11":
                  e['perjectTypeName'] = "报告送审"
                  e['perjectR_type'] = "reportTria"
                  break;
                case "12":
                  e['perjectTypeName'] = "技术评估"
                  e['perjectR_type'] = "technologyAssessment"
                  break;
                case "13":
                  e['perjectTypeName'] = "报告报批"
                  e['perjectR_type'] = "reportApproval"
                  break;
                case "14":
                  e['perjectTypeName'] = "报告公示"
                  e['perjectR_type'] = "reportPublicity"
                  break;
                case "15":
                  e['perjectTypeName'] = "报告存档"
                  e['perjectR_type'] = "reportArchives"
                  break;
                case "16":
                  e['perjectTypeName'] = "项目结束"
                  e['perjectR_type'] = "underway"
                  break;
              }
            });
            }
          } else {
            res.count = 0
            res.projectInfo = []
          }
          this.total = res.count
          this.listData = res.projectInfo
        })
      },
      changePage(page) {
        this.page = page
        console.log(this.page);
        this.getUnderway()
      },
      getInfo(id) {
        axios.get('/projectInformation/findProjectByID', {
          params: {
            Id,
          }
        }).then(res => {
          this.$store.commit('setProjectInfo', res.info)
        })
      }
    }
  }
</script>

<style scoped>
  .ivu-col-span-2:hover {
    cursor: pointer;
  }
</style>
